﻿#include "MailDialogs.h"
#include "../../MirGraphics/MLibrary.h"
#include "../../Settings.h"
#include "../../MirSounds/SoundManager.h"
#include "../../../Shared/Language.h"
#include "../GameScene.h"
#include "../../../Shared/Enums.h"
#include "../../../Shared/ClientPackets.h"
#include "../../MirNetwork/Network.h"

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirSounds;
using namespace Client::MirNetwork;
namespace C = ClientPackets;

namespace Client::MirScenes::Dialogs
{

    MailListDialog::MailListDialog()
    {
        setIndex(670);
        setLibrary(Libraries::Title);
        Size tempVar(312, 444);
        setSize(&tempVar);
        setMovable(true);
        setSort(true);
        Point tempVar2((Settings::ScreenWidth - getSize()->Width) - 150, 5);
        setLocation(&tempVar2);

        TitleLabel = new MirImageControl();
        TitleLabel->setIndex(7);
        TitleLabel->setLibrary(Libraries::Title);
        Point tempVar3(18, 9);
        TitleLabel->setLocation(&tempVar3);
        TitleLabel->setParent(this);

        TitleTypeLabel = new MirLabel();
        TitleTypeLabel->setText("TYPE");
        TitleTypeLabel->setParent(this);
        Font tempVar4(Settings::FontName, Settings::FontSize - 1, FontStyle::Italic);
        TitleTypeLabel->setFont(&tempVar4);
        TitleTypeLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar5(37, 19);
        TitleTypeLabel->setSize(&tempVar5);
        Point tempVar6(8, 34);
        TitleTypeLabel->setLocation(&tempVar6);

        TitleSenderLabel = new MirLabel();
        TitleSenderLabel->setText("SENDER");
        TitleSenderLabel->setParent(this);
        Font tempVar7(Settings::FontName, Settings::FontSize - 1, FontStyle::Italic);
        TitleSenderLabel->setFont(&tempVar7);
        TitleSenderLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar8(132, 19);
        TitleSenderLabel->setSize(&tempVar8);
        Point tempVar9(47, 34);
        TitleSenderLabel->setLocation(&tempVar9);

        TitleMessageLabel = new MirLabel();
        TitleMessageLabel->setText("MESSAGE");
        TitleMessageLabel->setParent(this);
        Font tempVar10(Settings::FontName, Settings::FontSize - 1, FontStyle::Italic);
        TitleMessageLabel->setFont(&tempVar10);
        TitleMessageLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar11(122, 19);
        TitleMessageLabel->setSize(&tempVar11);
        Point tempVar12(181, 34);
        TitleMessageLabel->setLocation(&tempVar12);

        CloseButton = new MirButton();
        CloseButton->setHoverIndex(361);
        CloseButton->setIndex(360);
        Point tempVar13(getSize()->Width - 24, 3);
        CloseButton->setLocation(&tempVar13);
        CloseButton->setLibrary(Libraries::Prguse2);
        CloseButton->setParent(this);
        CloseButton->setPressedIndex(362);
        CloseButton->setSound(SoundList::ButtonA);
        CloseButton->Click += [&] (o, e)
        {
            Hide();
        };

        HelpButton = new MirButton();
        HelpButton->setIndex(257);
        HelpButton->setHoverIndex(258);
        HelpButton->setPressedIndex(259);
        HelpButton->setLibrary(Libraries::Prguse2);
        HelpButton->setParent(this);
        Point tempVar14(getSize()->Width - 50, 3);
        HelpButton->setLocation(&tempVar14);
        HelpButton->setSound(SoundList::ButtonA);
        HelpButton->Click += [&] (o, e)
        {
            GameScene::Scene->HelpDialog->DisplayPage("");
        };

        PreviousButton = new MirButton();
        PreviousButton->setIndex(240);
        PreviousButton->setHoverIndex(241);
        PreviousButton->setPressedIndex(242);
        PreviousButton->setLibrary(Libraries::Prguse2);
        PreviousButton->setParent(this);
        Point tempVar15(102, getSize()->Height - 55);
        PreviousButton->setLocation(&tempVar15);
        PreviousButton->setSound(SoundList::ButtonA);
        PreviousButton->Click += [&] (o, e)
        {
            if (CurrentPage <= 1)
            {
                return;
            }
    
            SelectedMail = nullptr;
    
            CurrentPage--;
    
            StartIndex -= 10;
    
            UpdateInterface();
        };

        PageLabel = new MirLabel();
        PageLabel->setText("");
        PageLabel->setParent(this);
        Point tempVar16(120, getSize()->Height - 55);
        PageLabel->setLocation(&tempVar16);
        Size tempVar17(67, 15);
        PageLabel->setSize(&tempVar17);
        PageLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);

        NextButton = new MirButton();
        NextButton->setIndex(243);
        NextButton->setHoverIndex(244);
        NextButton->setPressedIndex(245);
        NextButton->setLibrary(Libraries::Prguse2);
        NextButton->setParent(this);
        Point tempVar18(192, getSize()->Height - 55);
        NextButton->setLocation(&tempVar18);
        NextButton->setSound(SoundList::ButtonA);
        NextButton->Click += [&] (o, e)
        {
            if (CurrentPage >= PageCount)
            {
                return;
            }
    
            SelectedMail = nullptr;
    
            CurrentPage++;
            StartIndex += 10;
    
            UpdateInterface();
        };

        #pragma region Action Buttons
        SendButton = new MirButton();
        SendButton->setIndex(563);
        SendButton->setHoverIndex(564);
        SendButton->setPressedIndex(565);
        SendButton->setLibrary(Libraries::Prguse);
        SendButton->setParent(this);
        Point tempVar19(75, 414);
        SendButton->setLocation(&tempVar19);
        SendButton->setSound(SoundList::ButtonA);
        SendButton->setHint(GameLanguage::Send);
        SendButton->Click += [&] (o, e)
        {
                MirInputBox *inputBox = new MirInputBox(GameLanguage::EnterMailToName);
    
                inputBox->OKButton->Click += [&] (o1, e1)
                {
                        //open letter dialog, pass in name
                        GameScene::Scene->MailComposeLetterDialog->ComposeMail(inputBox->InputTextBox->getText());

                        inputBox->Dispose();
                };
    
                inputBox->Show();

            delete inputBox;
        };

        ReplyButton = new MirButton();
        ReplyButton->setIndex(569);
        ReplyButton->setHoverIndex(570);
        ReplyButton->setPressedIndex(571);
        ReplyButton->setLibrary(Libraries::Prguse);
        ReplyButton->setParent(this);
        Point tempVar20(102, 414);
        ReplyButton->setLocation(&tempVar20);
        ReplyButton->setSound(SoundList::ButtonA);
        ReplyButton->setHint(GameLanguage::Reply);
        ReplyButton->Click += [&] (o, e)
        {
            if (SelectedMail == nullptr)
            {
                return;
            }
    
            GameScene::Scene->MailComposeLetterDialog->ComposeMail(SelectedMail->SenderName);
        };

        ReadButton = new MirButton();
        ReadButton->setIndex(572);
        ReadButton->setHoverIndex(573);
        ReadButton->setPressedIndex(574);
        ReadButton->setLibrary(Libraries::Prguse);
        ReadButton->setParent(this);
        Point tempVar21(129, 414);
        ReadButton->setLocation(&tempVar21);
        ReadButton->setSound(SoundList::ButtonA);
        ReadButton->setHint(GameLanguage::Read);
        ReadButton->Click += [&] (o, e)
        {
            if (SelectedMail == nullptr)
            {
                return;
            }
    
            if (SelectedMail->Gold > 0 || SelectedMail->Items.size() > 0)
            {
                GameScene::Scene->MailReadParcelDialog->ReadMail(SelectedMail);
            }
            else
            {
                GameScene::Scene->MailReadLetterDialog->ReadMail(SelectedMail);
            }
        };

        DeleteButton = new MirButton();
        DeleteButton->setIndex(557);
        DeleteButton->setHoverIndex(558);
        DeleteButton->setPressedIndex(559);
        DeleteButton->setLibrary(Libraries::Prguse);
        DeleteButton->setParent(this);
        Point tempVar22(156, 414);
        DeleteButton->setLocation(&tempVar22);
        DeleteButton->setSound(SoundList::ButtonA);
        DeleteButton->setHint(GameLanguage::Delete);
        DeleteButton->Click += [&] (o, e)
        {
            if (SelectedMail == nullptr || SelectedMail->Locked)
            {
                return;
            }
    
            if (SelectedMail->Items.size() > 0 || SelectedMail->Gold > 0)
            {
                MirMessageBox *messageBox = new MirMessageBox("This parcel contains items or gold. Are you sure you want to delete it?", MirMessageBoxButtons::YesNo);
    
                messageBox->YesButton->Click += [&] (o1, e1)
                {
                        C::DeleteMail *tempVar23 = new C::DeleteMail();
                        tempVar23->MailID = SelectedMail->MailID;
                        Network::Enqueue(tempVar23);
                        SelectedMail = nullptr;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar23' statement was not added since tempVar23 was passed to a method or constructor. Handle memory management manually.
                };
    
                messageBox->Show();

            delete messageBox;
            }
            else
            {
                C::DeleteMail *tempVar24 = new C::DeleteMail();
                tempVar24->MailID = SelectedMail->MailID;
                Network::Enqueue(tempVar24);
                SelectedMail = nullptr;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar24' statement was not added since tempVar24 was passed to a method or constructor. Handle memory management manually.
            }
        };

        BlockListButton = new MirButton();
        BlockListButton->setIndex(520);
        BlockListButton->setHoverIndex(521);
        BlockListButton->setPressedIndex(522);
        BlockListButton->setLibrary(Libraries::Prguse);
        BlockListButton->setParent(this);
        Point tempVar25(183, 414);
        BlockListButton->setLocation(&tempVar25);
        BlockListButton->setSound(SoundList::ButtonA);
        BlockListButton->setHint(GameLanguage::BlockList);
        BlockListButton->setGrayScale(true);
        BlockListButton->setEnabled(false);

        BugReportButton = new MirButton();
        BugReportButton->setIndex(523);
        BugReportButton->setHoverIndex(524);
        BugReportButton->setPressedIndex(525);
        BugReportButton->setLibrary(Libraries::Prguse);
        BugReportButton->setParent(this);
        Point tempVar26(210, 414);
        BugReportButton->setLocation(&tempVar26);
        BugReportButton->setSound(SoundList::ButtonA);
        BugReportButton->setHint("Report Bug");
        BugReportButton->setGrayScale(true);
        BugReportButton->setEnabled(false);
        #pragma endregion


    }

    void MailListDialog::Reset()
    {
        for (int i = 0; i < Rows.size(); i++)
        {
            if (Rows[i] != nullptr)
            {
                Rows[i]->Dispose();
            }

            Rows[i] = nullptr;
        }
    }

    void MailListDialog::UpdateInterface()
    {
        Reset();

        PageCount = static_cast<int>(std::ceil(static_cast<double>(GameScene::getUser()->Mail.size()) / 10));
        if (PageCount < 1)
        {
            PageCount = 1;
        }

        PageLabel->setText(StringHelper::formatSimple("{0} / {1}", CurrentPage, PageCount));

        for (int i = 0; i < Rows.size(); i++)
        {
            if (i + StartIndex >= GameScene::getUser()->Mail.size())
            {
                break;
            }

            if (Rows[i] != nullptr)
            {
                Rows[i]->Dispose();
            }

            MailItemRow *tempVar = new MailItemRow();
            tempVar->Mail = GameScene::getUser()->Mail[i + StartIndex];
            Point tempVar2(10, 55 + i * 33);
            tempVar->setLocation(&tempVar2);
            tempVar->setParent(this);
            Rows[i] = tempVar;

            Rows[i]->Click += [&] (o, e)
            {
                MailItemRow *row = static_cast<MailItemRow*>(o);
    
                if (row->Mail != SelectedMail)
                {
                    SelectedMail = row->Mail;
                    SelectedIndex = FindSelectedIndex();
                    UpdateRows();
                }
                else
                {
                    if (SelectedMail->Gold > 0 || SelectedMail->Items.size() > 0)
                    {
                        GameScene::Scene->MailReadParcelDialog->ReadMail(SelectedMail);
                    }
                    else
                    {
                        GameScene::Scene->MailReadLetterDialog->ReadMail(SelectedMail);
                    }
                }
            };

            if (SelectedMail != nullptr)
            {
                if (SelectedMail->MailID == Rows[i]->Mail.MailID)
                {
                    SelectedMail = Rows[i]->Mail;
                }
            }

            delete tempVar;
        }

        UpdateRows();
    }

    int MailListDialog::FindSelectedIndex()
    {
        int selectedIndex = 0;
        if (SelectedMail != nullptr)
        {
            for (int i = 0; i < Rows.size(); i++)
            {
                if (Rows[i] == nullptr || SelectedMail != Rows[i]->Mail)
                {
                    continue;
                }

                selectedIndex = i;
            }
        }

        return selectedIndex;
    }

    void MailListDialog::UpdateRows()
    {
        for (int i = 0; i < Rows.size(); i++)
        {
            if (Rows[i] == nullptr)
            {
                continue;
            }

            Rows[i]->Selected = false;

            if (Rows[i]->Mail == SelectedMail)
            {
                Rows[i]->Selected = true;
            }

            Rows[i]->UpdateInterface();
        }

        if (SelectedMail != nullptr)
        {
            ReplyButton->setVisible(SelectedMail->CanReply);
        }
    }

    void MailListDialog::Show()
    {
        if (getVisible())
        {
            return;
        }
        setVisible(true);

        UpdateInterface();
    }

    void MailListDialog::Hide()
    {
        if (!getVisible())
        {
            return;
        }
        setVisible(false);

        SelectedMail = nullptr;
        SelectedIndex = -1;
    }

    void MailListDialog::Toggle()
    {
        if (!getVisible())
        {
            Show();
        }
        else
        {
            Hide();
        }
    }

    MailItemRow::MailItemRow()
    {
        setSound(SoundList::ButtonA);
        Size tempVar(290, 33);
        setSize(&tempVar);

        BeforeDraw += QuestRow_BeforeDraw;

        IconImage = new MirImageControl();
        IconImage->setIndex(0);
        IconImage->setLibrary(Libraries::Prguse);
        Point tempVar2(0, 0);
        IconImage->setLocation(&tempVar2);
        IconImage->setParent(this);

        UnreadImage = new MirImageControl();
        UnreadImage->setIndex(550);
        UnreadImage->setLibrary(Libraries::Prguse);
        Point tempVar3(5, 17);
        UnreadImage->setLocation(&tempVar3);
        UnreadImage->setParent(this);
        UnreadImage->setVisible(false);

        LockedImage = new MirImageControl();
        LockedImage->setIndex(551);
        LockedImage->setLibrary(Libraries::Prguse);
        Point tempVar4(5, 17);
        LockedImage->setLocation(&tempVar4);
        LockedImage->setParent(this);
        LockedImage->setVisible(false);

        ParcelImage = new MirImageControl();
        ParcelImage->setIndex(552);
        ParcelImage->setLibrary(Libraries::Prguse);
        Point tempVar5(5, 17);
        ParcelImage->setLocation(&tempVar5);
        ParcelImage->setParent(this);
        ParcelImage->setVisible(false);


        SelectedImage = new MirImageControl();
        SelectedImage->setIndex(545);
        SelectedImage->setLibrary(Libraries::Prguse);
        Point tempVar6(-5, -3);
        SelectedImage->setLocation(&tempVar6);
        SelectedImage->setParent(this);
        SelectedImage->setVisible(false);
        SelectedImage->setNotControl(true);

        SenderLabel = new MirLabel();
        Point tempVar7(35, 0);
        SenderLabel->setLocation(&tempVar7);
        Size tempVar8(130, 31);
        SenderLabel->setSize(&tempVar8);
        SenderLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        SenderLabel->setParent(this);
        SenderLabel->setNotControl(true);

        MessageLabel = new MirLabel();
        Point tempVar9(170, 0);
        MessageLabel->setLocation(&tempVar9);
        Size tempVar10(115, 31);
        MessageLabel->setSize(&tempVar10);
        MessageLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        MessageLabel->setParent(this);
        MessageLabel->setNotControl(true);

        UpdateInterface();
    }

    void MailItemRow::QuestRow_BeforeDraw(std::any sender, EventArgs *e)
    {
        UpdateInterface();
    }

    void MailItemRow::UpdateInterface()
    {
        if (Mail == nullptr)
        {
            return;
        }

        IconImage->setVisible(true);

        if (Mail->Items.size() > 0)
        {
            IconImage->setIndex(Mail->Items[0]->Info.Image);
            IconImage->setLibrary(Libraries::Items);
        }
        else if (Mail->Gold > 0)
        {
            IconImage->setIndex(541);
            IconImage->setLibrary(Libraries::Prguse);
        }
        else
        {
            IconImage->setIndex(540);
            IconImage->setLibrary(Libraries::Prguse);
        }

        Point tempVar((IconArea->Width - IconImage->getSize()->Width) / 2, (IconArea->Height - IconImage->getSize()->Height) / 2);
        IconImage->setLocation(&tempVar);


        if (!Mail->Opened)
        {
            UnreadImage->setVisible(true);
        }

        if (Mail->Locked)
        {
            LockedImage->setVisible(true);
        }

        if (!Mail->Collected)
        {
            ParcelImage->setVisible(true);

            if (!Mail->Opened)
            {
                //move unread to second position if not collected parcel
                Point tempVar2(20, 17);
                UnreadImage->setLocation(&tempVar2);
            }
        }
        else
        {
            if (Mail->Locked)
            {
                //move unread to second position if locked
                Point tempVar3(20, 17);
                UnreadImage->setLocation(&tempVar3);
            }
        }

        SenderLabel->setText(Mail->SenderName);
        MessageLabel->setText(Mail->Locked ? "[*] " + StringHelper::replace(Mail->Message, "\r\n", " ") : StringHelper::replace(Mail->Message, "\r\n", " "));

        SelectedImage->setVisible(Selected);
    }

    void MailItemRow::Dispose(bool disposing)
    {
        MirControl::Dispose(disposing);

        Mail = nullptr;
        SenderLabel = nullptr;
        MessageLabel = nullptr;
        SelectedImage = nullptr;
        IconImage = nullptr;

        Selected = false;
    }

    void MailItemRow::OnMouseEnter()
    {
        MirControl::OnMouseEnter();
        GameScene::Scene->CreateMailLabel(Mail);
    }

    void MailItemRow::OnMouseLeave()
    {
        MirControl::OnMouseLeave();
        GameScene::Scene->DisposeMailLabel();
    }

    MailComposeLetterDialog::MailComposeLetterDialog()
    {
        setIndex(671);
        setLibrary(Libraries::Title);
        Size tempVar(236, 300);
        setSize(&tempVar);
        setMovable(true);
        setSort(true);
        Point tempVar2(100, 100);
        setLocation(&tempVar2);

        CloseButton = new MirButton();
        CloseButton->setHoverIndex(361);
        CloseButton->setIndex(360);
        Point tempVar3(getSize()->Width - 27, 3);
        CloseButton->setLocation(&tempVar3);
        CloseButton->setLibrary(Libraries::Prguse2);
        CloseButton->setParent(this);
        CloseButton->setPressedIndex(362);
        CloseButton->setSound(SoundList::ButtonA);
        CloseButton->Click += [&] (o, e)
        {
            Hide();
        };


        RecipientNameLabel = new MirLabel();
        RecipientNameLabel->setText("");
        RecipientNameLabel->setParent(this);
        Font tempVar4(Settings::FontName, 8.0F);
        RecipientNameLabel->setFont(&tempVar4);
        RecipientNameLabel->setForeColour(Color::White);
        Point tempVar5(70, 35);
        RecipientNameLabel->setLocation(&tempVar5);
        Size tempVar6(150, 15);
        RecipientNameLabel->setSize(&tempVar6);
        RecipientNameLabel->setNotControl(true);

        MessageTextBox = new MirTextBox();
        MessageTextBox->setForeColour(Color::White);
        MessageTextBox->setParent(this);
        Font tempVar7(Settings::FontName, 8.0F);
        MessageTextBox->setFont(&tempVar7);
        Point tempVar8(15, 92);
        MessageTextBox->setLocation(&tempVar8);
        Size tempVar9(202, 165);
        MessageTextBox->setSize(&tempVar9);

        MessageTextBox->MultiLine();

        SendButton = new MirButton();
        SendButton->setIndex(607);
        SendButton->setHoverIndex(608);
        SendButton->setPressedIndex(609);
        SendButton->setParent(this);
        SendButton->setLibrary(Libraries::Title);
        SendButton->setSound(SoundList::ButtonA);
        Point tempVar10(30, 265);
        SendButton->setLocation(&tempVar10);
        SendButton->Click += [&] (o, e)
        {
            C::SendMail *tempVar11 = new C::SendMail();
            tempVar11->Name = RecipientNameLabel->getText();
            tempVar11->Message = MessageTextBox->getText();
            Network::Enqueue(tempVar11);
            Hide();

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar11' statement was not added since tempVar11 was passed to a method or constructor. Handle memory management manually.
        };

        CancelButton = new MirButton();
        CancelButton->setIndex(193);
        CancelButton->setHoverIndex(194);
        CancelButton->setPressedIndex(195);
        CancelButton->setParent(this);
        CancelButton->setLibrary(Libraries::Title);
        CancelButton->setSound(SoundList::ButtonA);
        Point tempVar12(135, 265);
        CancelButton->setLocation(&tempVar12);
        CancelButton->Click += [&] (o, e)
        {
            Hide();
        };
    }

    void MailComposeLetterDialog::ComposeMail(const std::string &recipientName, const std::string &message)
    {
        if (recipientName.empty())
        {
            return;
        }

        RecipientNameLabel->setText(recipientName);
        MessageTextBox->setText(message);

        MessageTextBox->SetFocus();

        setVisible(true);
    }

std::vector<UserItem*> MailComposeParcelDialog::Items(_cellCount);
std::vector<unsigned long long> MailComposeParcelDialog::ItemsIdx(_cellCount);

    MailComposeParcelDialog::MailComposeParcelDialog()
    {
        setIndex(674);
        setLibrary(Libraries::Title);
        Size tempVar(236, 384);
        setSize(&tempVar);
        setMovable(true);
        setSort(true);
        Point tempVar2(GameScene::Scene->InventoryDialog->getSize()->Width + 10, 0);
        setLocation(&tempVar2);

        CloseButton = new MirButton();
        CloseButton->setHoverIndex(361);
        CloseButton->setIndex(360);
        Point tempVar3(getSize()->Width - 27, 3);
        CloseButton->setLocation(&tempVar3);
        CloseButton->setLibrary(Libraries::Prguse2);
        CloseButton->setParent(this);
        CloseButton->setPressedIndex(362);
        CloseButton->setSound(SoundList::ButtonA);
        CloseButton->Click += [&] (o, e)
        {
            ResetLockedCells();
            Hide();
        };

        RecipientNameLabel = new MirLabel();
        RecipientNameLabel->setText("");
        RecipientNameLabel->setParent(this);
        Font tempVar4(Settings::FontName, 8.0F);
        RecipientNameLabel->setFont(&tempVar4);
        RecipientNameLabel->setForeColour(Color::White);
        Point tempVar5(70, 35);
        RecipientNameLabel->setLocation(&tempVar5);
        Size tempVar6(150, 15);
        RecipientNameLabel->setSize(&tempVar6);
        RecipientNameLabel->setNotControl(true);

        MessageTextBox = new MirTextBox();
        MessageTextBox->setForeColour(Color::White);
        MessageTextBox->setParent(this);
        Font tempVar7(Settings::FontName, 8.0F);
        MessageTextBox->setFont(&tempVar7);
        Point tempVar8(15, 98);
        MessageTextBox->setLocation(&tempVar8);
        Size tempVar9(202, 165);
        MessageTextBox->setSize(&tempVar9);

        MessageTextBox->MultiLine();

        StampButton = new MirButton();
        StampButton->setIndex(203);
        StampButton->setHoverIndex(203);
        StampButton->setPressedIndex(203);
        Point tempVar10(73, 56);
        StampButton->setLocation(&tempVar10);
        Size tempVar11(20,20);
        StampButton->setSize(&tempVar11);
        StampButton->setLibrary(Libraries::Prguse2);
        StampButton->setParent(this);
        StampButton->setSound(SoundList::ButtonA);
        StampButton->Click += [&] (o, e)
        {
            StampParcel();
        };

        ItemCover = new MirImageControl();
        ItemCover->setIndex(676);
        Point tempVar12(63, 310);
        ItemCover->setLocation(&tempVar12);
        Size tempVar13(144, 33);
        ItemCover->setSize(&tempVar13);
        ItemCover->setLibrary(Libraries::Title);
        ItemCover->setParent(this);

        for (int i = 0; i < Cells.size(); i++)
        {
            MirItemCell *tempVar14 = new MirItemCell();
            tempVar14->setBorderColour(Color::Lime);
            Size tempVar15(35, 31);
            tempVar14->setSize(&tempVar15);
            tempVar14->setGridType(MirGridType::Mail);
            tempVar14->setLibrary(Libraries::Items);
            tempVar14->setParent(this);
            Point tempVar16(27 + (i * 36), 311);
            tempVar14->setLocation(&tempVar16);
            tempVar14->setItemSlot(i);
            Cells[i] = tempVar14;

            delete tempVar14;
        }

        ParcelCostLabel = new MirLabel();
        ParcelCostLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        Font tempVar17(Settings::FontName, 8.0F);
        ParcelCostLabel->setFont(&tempVar17);
        Point tempVar18(63, 269);
        ParcelCostLabel->setLocation(&tempVar18);
        ParcelCostLabel->setParent(this);
        Size tempVar19(143, 15);
        ParcelCostLabel->setSize(&tempVar19);

        GoldSendLabel = new MirLabel();
        GoldSendLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        Font tempVar20(Settings::FontName, 8.0F);
        GoldSendLabel->setFont(&tempVar20);
        Point tempVar21(63, 290);
        GoldSendLabel->setLocation(&tempVar21);
        GoldSendLabel->setParent(this);
        Size tempVar22(143, 15);
        GoldSendLabel->setSize(&tempVar22);
        GoldSendLabel->setSound(SoundList::Gold);
        GoldSendLabel->Click += [&] (o, e)
        {
            if (GameScene::SelectedCell == nullptr && GameScene::Gold > 0)
            {
                MirAmountBox *amountBox = new MirAmountBox("Send Amount:", 116, GameScene::Gold);
    
                amountBox->OKButton->Click += [&] (c, a)
                {
                        if (amountBox->Amount > 0)
                        {
                            GiftGoldAmount += amountBox->Amount;
                            GameScene::Gold -= amountBox->Amount;
                        }

                        GoldSendLabel->setText(GiftGoldAmount.ToString("###,###,##0"));

                        CalculatePostage();
                };
    
                amountBox->Show();
                GameScene::PickedUpGold = false;

            delete amountBox;
            }
        };

        SendButton = new MirButton();
        SendButton->setIndex(607);
        SendButton->setHoverIndex(608);
        SendButton->setPressedIndex(609);
        SendButton->setParent(this);
        SendButton->setLibrary(Libraries::Title);
        SendButton->setSound(SoundList::ButtonA);
        Point tempVar23(30, 350);
        SendButton->setLocation(&tempVar23);
        SendButton->Click += [&] (o, e)
        {
            C::SendMail *tempVar24 = new C::SendMail();
            tempVar24->Name = RecipientNameLabel->getText();
            tempVar24->Message = MessageTextBox->getText();
            tempVar24->Gold = GiftGoldAmount;
            tempVar24->ItemsIdx = ItemsIdx;
            tempVar24->Stamped = Stamped;
            Network::Enqueue(tempVar24);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar24' statement was not added since tempVar24 was passed to a method or constructor. Handle memory management manually.
        };

        CancelButton = new MirButton();
        CancelButton->setIndex(193);
        CancelButton->setHoverIndex(194);
        CancelButton->setPressedIndex(195);
        CancelButton->setParent(this);
        CancelButton->setLibrary(Libraries::Title);
        CancelButton->setSound(SoundList::ButtonA);
        Point tempVar25(135, 350);
        CancelButton->setLocation(&tempVar25);
        CancelButton->Click += [&] (o, e)
        {
            ResetLockedCells();
            Hide();
        };
    }

    void MailComposeParcelDialog::Hide()
    {
        if (!getVisible())
        {
            return;
        }
        setVisible(false);

        Reset();
    }

    void MailComposeParcelDialog::Reset()
    {
        GameScene::Gold += GiftGoldAmount;
        GiftGoldAmount = 0;
        Stamped = false;

        ResetLockedCells();
    }

    void MailComposeParcelDialog::ResetLockedCells()
    {
        for (int i = 0; i < _cellCount; i++)
        {
            MirItemCell *cell = Cells[i];

            if (cell->getItem() != nullptr)
            {
                C::MailLockedItem *tempVar = new C::MailLockedItem();
                tempVar->UniqueID = cell->getItem()->UniqueID;
                tempVar->Locked = false;
                Network::Enqueue(tempVar);
                cell->setItem(nullptr);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
            }

            ItemsIdx[i] = 0;
        }
    }

    void MailComposeParcelDialog::StampParcel()
    {
        if (!Stamped)
        {
            for (int i = 0; i < GameScene::getUser()->Inventory.size(); i++)
            {
                UserItem *item = GameScene::getUser()->Inventory[i];
                if (item == nullptr || item->Info->Type != ItemType::Nothing || item->Info->Shape != 1)
                {
                    continue;
                }

                Stamped = true;
                break;
            }
        }
        else
        {
            Stamped = false;
        }

        CalculatePostage();
        UpdateParcel();
        ResetLockedCells();
    }

    void MailComposeParcelDialog::UpdateParcel()
    {
        if (Stamped)
        {
            StampButton->setIndex(204);
            StampButton->setHoverIndex(204);
            StampButton->setPressedIndex(204);

            for (int i = 1; i < Cells.size(); i++)
            {
                Cells[i]->setEnabled(true);
            }

            ItemCover->setVisible(false);
        }
        else
        {
            StampButton->setIndex(203);
            StampButton->setHoverIndex(203);
            StampButton->setPressedIndex(203);

            for (int i = 1; i < Cells.size(); i++)
            {
                Cells[i]->setEnabled(false);
            }

            ItemCover->setVisible(true);
        }
    }

    void MailComposeParcelDialog::CalculatePostage()
    {
        C::MailCost *tempVar = new C::MailCost();
        tempVar->Gold = GiftGoldAmount;
        tempVar->ItemsIdx = ItemsIdx;
        tempVar->Stamped = Stamped;
        Network::Enqueue(tempVar);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    void MailComposeParcelDialog::ComposeMail(const std::string &recipientName)
    {
        if (recipientName.empty())
        {
            return;
        }

        RecipientNameLabel->setText(recipientName);
        MessageTextBox->setText("");
        MessageTextBox->SetFocus();

        UpdateParcel();

        //Disable last 4 item slots
        for (int i = 1; i < Cells.size(); i++)
        {
            Cells[i]->setEnabled(false);
        }

        ParcelCostLabel->setText("0");
        GoldSendLabel->setText("0");

        ResetLockedCells();

        setVisible(true);
    }

    MailReadLetterDialog::MailReadLetterDialog()
    {
        setIndex(672);
        setLibrary(Libraries::Title);
        Size tempVar(236, 300);
        setSize(&tempVar);
        setMovable(true);
        setSort(true);
        Point tempVar2(100, 100);
        setLocation(&tempVar2);

        CloseButton = new MirButton();
        CloseButton->setHoverIndex(361);
        CloseButton->setIndex(360);
        Point tempVar3(getSize()->Width - 27, 3);
        CloseButton->setLocation(&tempVar3);
        CloseButton->setLibrary(Libraries::Prguse2);
        CloseButton->setParent(this);
        CloseButton->setPressedIndex(362);
        CloseButton->setSound(SoundList::ButtonA);
        CloseButton->Click += [&] (o, e)
        {
            Hide();
        };

        SenderNameLabel = new MirLabel();
        SenderNameLabel->setParent(this);
        Font tempVar4(Settings::FontName, 8.0F);
        SenderNameLabel->setFont(&tempVar4);
        SenderNameLabel->setForeColour(Color::White);
        Point tempVar5(70, 35);
        SenderNameLabel->setLocation(&tempVar5);
        Size tempVar6(150, 15);
        SenderNameLabel->setSize(&tempVar6);
        SenderNameLabel->setNotControl(true);

        DateSentLabel = new MirLabel();
        DateSentLabel->setParent(this);
        Font tempVar7(Settings::FontName, 8.0F);
        DateSentLabel->setFont(&tempVar7);
        DateSentLabel->setForeColour(Color::White);
        Point tempVar8(70, 56);
        DateSentLabel->setLocation(&tempVar8);
        Size tempVar9(150, 15);
        DateSentLabel->setSize(&tempVar9);
        DateSentLabel->setNotControl(true);

        MessageLabel = new MirLabel();
        MessageLabel->setForeColour(Color::White);
        MessageLabel->setParent(this);
        Font tempVar10(Settings::FontName, 8.0F);
        MessageLabel->setFont(&tempVar10);
        Point tempVar11(15, 92);
        MessageLabel->setLocation(&tempVar11);
        Size tempVar12(202, 165);
        MessageLabel->setSize(&tempVar12);

        DeleteButton = new MirButton();
        DeleteButton->setIndex(540);
        DeleteButton->setHoverIndex(541);
        DeleteButton->setPressedIndex(542);
        DeleteButton->setParent(this);
        DeleteButton->setLibrary(Libraries::Title);
        DeleteButton->setSound(SoundList::ButtonA);
        Point tempVar13(12, 265);
        DeleteButton->setLocation(&tempVar13);
        DeleteButton->Click += [&] (o, e)
        {
            if (Mail->Locked)
            {
                return;
            }
    
            C::DeleteMail *tempVar14 = new C::DeleteMail();
            tempVar14->MailID = Mail->MailID;
            Network::Enqueue(tempVar14);
    
            Mail = nullptr;
    
            Hide();

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar14' statement was not added since tempVar14 was passed to a method or constructor. Handle memory management manually.
        };

        LockButton = new MirButton();
        LockButton->setIndex(686);
        LockButton->setHoverIndex(687);
        LockButton->setPressedIndex(688);
        LockButton->setParent(this);
        LockButton->setLibrary(Libraries::Title);
        LockButton->setSound(SoundList::ButtonA);
        Point tempVar15(81, 265);
        LockButton->setLocation(&tempVar15);
        LockButton->Click += [&] (o, e)
        {
            Mail->Locked = !Mail->Locked;
    
            //GameScene.Scene.MailListDialog.SelectedMail = null;
    
            C::LockMail *tempVar16 = new C::LockMail();
            tempVar16->MailID = Mail->MailID;
            tempVar16->Lock = Mail->Locked;
            Network::Enqueue(tempVar16);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar16' statement was not added since tempVar16 was passed to a method or constructor. Handle memory management manually.
        };

        CancelButton = new MirButton();
        CancelButton->setIndex(193);
        CancelButton->setHoverIndex(194);
        CancelButton->setPressedIndex(195);
        CancelButton->setParent(this);
        CancelButton->setLibrary(Libraries::Title);
        CancelButton->setSound(SoundList::ButtonA);
        Point tempVar17(154, 265);
        CancelButton->setLocation(&tempVar17);
        CancelButton->Click += [&] (o, e)
        {
            Hide();
        };
    }

    void MailReadLetterDialog::ReadMail(ClientMail *mail)
    {
        if (mail == nullptr)
        {
            return;
        }

        Mail = mail;

        if (!Mail->Opened)
        {
            C::ReadMail *tempVar = new C::ReadMail();
            tempVar->MailID = Mail->MailID;
            Network::Enqueue(tempVar);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
        }

        SenderNameLabel->setText(Mail->SenderName);
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
        DateSentLabel->setText(Mail->DateSent.ToString("dd/MM/yy H:mm:ss"));
        MessageLabel->setText(StringHelper::replace(Mail->Message, "\\r\\n", "\r\n"));

        setVisible(true);
    }

    MailReadParcelDialog::MailReadParcelDialog()
    {
        setIndex(675);
        setLibrary(Libraries::Title);
        Size tempVar(236, 300);
        setSize(&tempVar);
        setMovable(true);
        setSort(true);
        Point tempVar2(100, 100);
        setLocation(&tempVar2);

        CloseButton = new MirButton();
        CloseButton->setHoverIndex(361);
        CloseButton->setIndex(360);
        Point tempVar3(getSize()->Width - 27, 3);
        CloseButton->setLocation(&tempVar3);
        CloseButton->setLibrary(Libraries::Prguse2);
        CloseButton->setParent(this);
        CloseButton->setPressedIndex(362);
        CloseButton->setSound(SoundList::ButtonA);
        CloseButton->Click += [&] (o, e)
        {
            Hide();
        };

        SenderNameLabel = new MirLabel();
        SenderNameLabel->setParent(this);
        Font tempVar4(Settings::FontName, 8.0F);
        SenderNameLabel->setFont(&tempVar4);
        SenderNameLabel->setForeColour(Color::White);
        Point tempVar5(70, 35);
        SenderNameLabel->setLocation(&tempVar5);
        Size tempVar6(150, 15);
        SenderNameLabel->setSize(&tempVar6);
        SenderNameLabel->setNotControl(true);

        DateSentLabel = new MirLabel();
        DateSentLabel->setParent(this);
        Font tempVar7(Settings::FontName, 8.0F);
        DateSentLabel->setFont(&tempVar7);
        DateSentLabel->setForeColour(Color::White);
        Point tempVar8(70, 56);
        DateSentLabel->setLocation(&tempVar8);
        Size tempVar9(150, 15);
        DateSentLabel->setSize(&tempVar9);
        DateSentLabel->setNotControl(true);

        MessageLabel = new MirLabel();
        MessageLabel->setForeColour(Color::White);
        MessageLabel->setParent(this);
        Font tempVar10(Settings::FontName, 8.0F);
        MessageLabel->setFont(&tempVar10);
        Point tempVar11(15, 98);
        MessageLabel->setLocation(&tempVar11);
        Size tempVar12(202, 165);
        MessageLabel->setSize(&tempVar12);

        GoldSendLabel = new MirLabel();
        GoldSendLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        Font tempVar13(Settings::FontName, 8.0F);
        GoldSendLabel->setFont(&tempVar13);
        Point tempVar14(63, 290);
        GoldSendLabel->setLocation(&tempVar14);
        GoldSendLabel->setParent(this);
        Size tempVar15(143, 15);
        GoldSendLabel->setSize(&tempVar15);

        CollectButton = new MirButton();
        CollectButton->setIndex(370);
        CollectButton->setHoverIndex(371);
        CollectButton->setPressedIndex(372);
        CollectButton->setParent(this);
        CollectButton->setLibrary(Libraries::Title);
        CollectButton->setSound(SoundList::ButtonA);
        Point tempVar16(30, 350);
        CollectButton->setLocation(&tempVar16);
        CollectButton->Click += [&] (o, e)
        {
            C::CollectParcel *tempVar17 = new C::CollectParcel();
            tempVar17->MailID = Mail->MailID;
            Network::Enqueue(tempVar17);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar17' statement was not added since tempVar17 was passed to a method or constructor. Handle memory management manually.
        };

        CancelButton = new MirButton();
        CancelButton->setIndex(193);
        CancelButton->setHoverIndex(194);
        CancelButton->setPressedIndex(195);
        CancelButton->setParent(this);
        CancelButton->setLibrary(Libraries::Title);
        CancelButton->setSound(SoundList::ButtonA);
        Point tempVar18(135, 350);
        CancelButton->setLocation(&tempVar18);
        CancelButton->Click += [&] (o, e)
        {
            Hide();
        };
    }

    void MailReadParcelDialog::ReadMail(ClientMail *mail)
    {
        if (mail == nullptr)
        {
            return;
        }

        Mail = mail;

        if (!Mail->Opened)
        {
            C::ReadMail *tempVar = new C::ReadMail();
            tempVar->MailID = Mail->MailID;
            Network::Enqueue(tempVar);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
        }

        ResetCells();

        SenderNameLabel->setText(Mail->SenderName);
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
        DateSentLabel->setText(Mail->DateSent.ToString("dd/MM/yy H:mm:ss"));
        MessageLabel->setText(StringHelper::replace(Mail->Message, "\\r\\n", "\r\n"));
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
        GoldSendLabel->setText(Mail->Gold.ToString("###,###,##0"));

        if (Mail->Items.size() > 0)
        {
            for (int i = 0; i < Cells.size(); i++)
            {
                if (i >= Mail->Items.size())
                {
                    break;
                }

                MirItemCell *tempVar2 = new MirItemCell();
                tempVar2->setBorderColour(Color::Lime);
                Size tempVar3(35, 31);
                tempVar2->setSize(&tempVar3);
                tempVar2->setGridType(MirGridType::Mail);
                tempVar2->setLibrary(Libraries::Items);
                tempVar2->setParent(this);
                Point tempVar4(27 + (i * 36), 311);
                tempVar2->setLocation(&tempVar4);
                tempVar2->setItemSlot(i);
                tempVar2->setItem(Mail->Items[i]);
                Cells[i] = tempVar2;

                delete tempVar2;
            }
        }

        if (!Mail->Collected)
        {
            CollectButton->setIndex(683);
            CollectButton->setHoverIndex(684);
            CollectButton->setPressedIndex(685);
            CollectButton->setEnabled(false);
        }
        else
        {
            CollectButton->setIndex(680);
            CollectButton->setHoverIndex(681);
            CollectButton->setPressedIndex(682);
            CollectButton->setEnabled(true);
        }

        setVisible(true);
    }

    void MailReadParcelDialog::ResetCells()
    {
        for (auto item : Cells)
        {
            if (item == nullptr)
            {
                continue;
            }

            if (item->getItem() != nullptr)
            {
                item->setItem(nullptr);
            }
        }
    }
}
